package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.vo.DelayedCareVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseClaim;
import com.ktgj.customer.service.ICaseClaimService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 理赔工单Controller
 * 
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/claim")
public class CaseClaimController extends BaseController
{
    @Autowired
    private ICaseClaimService caseClaimService;

    /**
     * 查询理赔工单列表
     */
    @PreAuthorize(hasPermi = "system:claim:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseClaim caseClaim)
    {
        startPage();
        List<CaseClaim> list = caseClaimService.selectCaseClaimList(caseClaim);
        return getDataTable(list);
    }

    /**
     * 导出理赔工单列表
     */
    @PreAuthorize(hasPermi = "system:claim:export")
    @Log(title = "理赔工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseClaim caseClaim) throws IOException
    {
        List<CaseClaim> list = caseClaimService.selectCaseClaimList(caseClaim);
        ExcelUtil<CaseClaim> util = new ExcelUtil<CaseClaim>(CaseClaim.class);
        util.exportExcel(response, list, "理赔工单数据");
    }

    /**
     * 获取理赔工单详细信息
     */
//    @PreAuthorize(hasPermi = "system:claim:query")
    @PostMapping("/claimById")
    public AjaxResult getInfo(@RequestBody Map<String, Object> map)
    {
        Long claimId =  Long.valueOf(map.get("claimId").toString());
        return AjaxResult.success(caseClaimService.selectCaseClaimById(claimId));
    }

    /**
     * 新增理赔工单
     */
    @PreAuthorize(hasPermi = "system:claim:add")
    @Log(title = "理赔工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseClaim caseClaim)
    {
        return toAjax(caseClaimService.insertCaseClaim(caseClaim));
    }

    /**
     * 修改理赔工单
     */
//    @PreAuthorize(hasPermi = "system:claim:edit")
//    @Log(title = "理赔工单", businessType = BusinessType.UPDATE)
//    @PutMapping
    @PostMapping("/claimEdit")
    public AjaxResult edit(@RequestBody CaseClaim caseClaim)
    {
        return toAjax(caseClaimService.updateCaseClaim(caseClaim));
    }

    /**
     * 删除理赔工单
     */
    @PreAuthorize(hasPermi = "system:claim:remove")
    @Log(title = "理赔工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseClaimIds}")
    public AjaxResult remove(@PathVariable Long[] caseClaimIds)
    {
        return toAjax(caseClaimService.deleteCaseClaimByIds(caseClaimIds));
    }

    /**
     * 延误关怀
     * */
    @PostMapping("/caseClaimList")
    public AjaxResult caseClaimList(HttpServletRequest request) {
        List<DelayedCareVo> delayedCareVoList;
        try {
            delayedCareVoList = caseClaimService.caseClaimList(request);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(delayedCareVoList);
    }
}
